using UnityEngine;
using System.Collections;

public class CameraActionViewState :State<CameraControl> 
{
	#region Singleton

    private static CameraActionViewState instance = new CameraActionViewState();
    public static CameraActionViewState Instance { get { return instance; } }
    private CameraActionViewState() { }

    #endregion

    #region State

    public override void OnEnter(CameraControl behaviour)
    {
		behaviour.actionView = true;
        behaviour.notifyActionViewCompleted = true;
    }

    public override void OnUpdate(CameraControl behaviour)
    {
		behaviour.currentTargetDistance = behaviour.transform.position + behaviour.distance;
		behaviour.moveDistance = behaviour.CalculateMoveDistance(behaviour.actionViewPos);
        behaviour.Move(behaviour.moveDistance, behaviour.currentTargetDistance);

        if ((GameObject.FindGameObjectWithTag(TagConstants.TAG_CAMERA).transform.position - behaviour.actionViewPos).magnitude < 0.1 &&
            behaviour.notifyActionViewCompleted)
        {
            behaviour.receiver.Action();
            behaviour.notifyActionViewCompleted = false;
        }
        // Final Tasks
        behaviour.targetDistance = behaviour.currentTargetDistance;
        behaviour.mainCamera.transform.eulerAngles = behaviour.camRotation;
		
        
    }

    public override void OnExit(CameraControl behaviour)
    {
        behaviour.actionView = false;
        behaviour.notifyActionViewCompleted = false;
    }

    public override void OnAction(string name, CameraControl behaviour, object value)
    {
    }

    #endregion
}
